home *** CD-ROM | disk | FTP | other *** search
Text File | 1996-05-21 | 2.1 KB | 68 lines | [TEXT/ttxt] |
- in module AnalogClockModule
-
- class RotatingShape (TwoDPresenter)
- instance variables
- rotMatrix
- workMatrix
- xDiff
- yDiff
- fill
- stroke
- end
- method draw self {class RotatingShape} theSurface theClip ->
- (
- nextMethod self theSurface theClip
- local workMatrix := self.workMatrix
- setTo workMatrix self.rotMatrix
- translate workMatrix (self.x + self.xDiff) (self.y + self.yDiff)
- if (self.fill <> undefined) do
- fill theSurface self.target theClip workMatrix self.fill
- if (self.stroke <> undefined) do
- stroke theSurface self.target theClip workMatrix self.stroke
- -- For debugging only - check the boundary.
- -- stroke theSurface self.boundary theClip self.globalTransform blackBrush
- self
- )
- method rotate self {class RotatingShape} amount units ->
- (
- rotate self.rotMatrix amount units
- notifyChanged self false
- )
- method init self {class RotatingShape} #rest args #key \
- fill:(undefined) stroke:(undefined) \
- axisPos:(new Point x:0 y:0) ->
- (
- apply nextMethod self args
- self.fill := fill
- self.stroke := stroke
- self.xDiff := axisPos.x
- self.yDiff := axisPos.y
- )
- method afterInit self {class RotatingShape} #rest args ->
- (
- apply nextMethod self args
- if ((self.fill = undefined) and (isAKindOf self.target Bitmap)) do
- self.fill := defaultBrush
- self.workMatrix := mutableCopy identityMatrix
- -- Rotation is always around [0,0].
- self.rotMatrix := translate (mutableCopy identityMatrix) \
- (-self.xDiff) (-self.yDiff)
- -- The largest box needed to contain the rotation
- -- has sides twice the length of the maximum diagonal
- -- of the rotation.
- local tBbox := transform self.target.bbox self.rotMatrix @create
- local n := (ceiling (sqrt (max \
- ((tBbox.x1 * tBbox.x1) + (tBbox.y1 * tBbox.y1)) \
- ((tBbox.x2 * tBbox.x2) + (tBbox.y2 * tBbox.y2)) \
- ))) * 2
- -- Allow room for a border stroke. (NOTE: Because this is only
- -- calcuated during instance creation, you cant change the stroke IV.
- -- This restriction could be removed by specializing strokeSetter.)
- if (self.stroke <> undefined) do
- n := n + (self.stroke.lineWidth * 2)
- self.boundary := new Rect x1:(self.xDiff - n/2) x2:(self.xDiff + n/2) \
- y1:(self.yDiff - n/2) y2:(self.yDiff + n/2)
- )
-
- "Loaded rot8shp.sx"
-